package cn.ywang.pattern.template;


import javax.sql.DataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * @author BeatificWang
 * @date 2019/3/18 22:48
 */

public class UserDao extends JdbcTemplate {

	public UserDao(DataSource dataSource) {
		super(dataSource);
	}

	public List<?> selectUserList() {
		String sql = "select * from user";

		return super.executeQuery(sql, null, new RowMapper<User>() {

			/**
			 * 处理单行
			 *
			 * @param resultSet
			 * @param rowNum
			 * @return
			 * @throws SQLException
			 */
			@Override
			public User mapRow(ResultSet resultSet, int rowNum) throws SQLException {
				User user = new User();
				user.setAge(resultSet.getInt("age"));
				user.setName(resultSet.getString("name"));
				user.setActive(resultSet.getString("active"));
				return user;
			}
		});
	}
}
